package h.c.z.designPattern.B01_Strategy;

/**
 * 说明：
 * @author jinsicao
 * @version 2016年12月15日
 */
public class Client {
	
	public static void main(String[] args) {
		double goodsPrice = 100;
		int quantity = 10;
		// 正常处理
//		normalPrice(goodsPrice, quantity);
		// 简单工厂处理
//		simpleFactory(goodsPrice, quantity);
		// 策略模式
		strategy(goodsPrice, quantity);
	}
	
	public static void strategy(double goodsPrice, int quantity) {
		String type = "正常";
		Context context = new Context(new NormalStrategy());
		print(type, context.calculatePrice(goodsPrice, quantity));
		
		type = "打5折";
		context = new Context(new RebateStrategy(0.5));
		print(type, context.calculatePrice(goodsPrice, quantity));
		
		type = "打8折";
		context = new Context(new RebateStrategy(0.8));
		print(type, context.calculatePrice(goodsPrice, quantity));
		
		type = "满500减20";
		context = new Context(new ReturnStrategy(500, 20));
		print(type, context.calculatePrice(goodsPrice, quantity));
		
		type = "满200减10";
		context = new Context(new ReturnStrategy(200, 10));
		print(type, context.calculatePrice(goodsPrice, quantity));
	}
	
	public static void simpleFactory(double goodsPrice, int quantity) {
		String type = "打5折";
		print(type, PriceFactory.calculatePrice(goodsPrice, quantity, type));
		type = "打8折";
		print(type, PriceFactory.calculatePrice(goodsPrice, quantity, type));
		type = "满500减20";
		print(type, PriceFactory.calculatePrice(goodsPrice, quantity, type));
		type = "满200减10";
		print(type, PriceFactory.calculatePrice(goodsPrice, quantity, type));
	}
	
	public static void normalPrice(double goodsPrice, int quantity) {
		Price price = new PriceImpl();
		String type = "打5折";
		print(type, price.calculatePrice(goodsPrice, quantity, type));
		type = "打8折";
		print(type, price.calculatePrice(goodsPrice, quantity, type));
		type = "满500减20";
		print(type, price.calculatePrice(goodsPrice, quantity, type));
		type = "满200减10";
		print(type, price.calculatePrice(goodsPrice, quantity, type));
	}
	
	
	private static void print(String type, double totalPrice) {
		System.out.println(type + ": " + totalPrice);
	}

}
